/*--------------------------------------------------------------------------------*/
#ifndef __GRAPHIC_VERTEX_BUFFER__
#define __GRAPHIC_VERTEX_BUFFER__
/*--------------------------------------------------------------------------------*/
#include "primitives.h"
#include "object.h"
#include "util.h"
#include "ref_to_.h"
#include <GL/gl.h>
#include <GL/glext.h>
#include "debug.h"
/*--------------------------------------------------------------------------------*/
class GRAPHIC_VERTEX_BUFFER : public OBJECT
{

public:

    DECLARE_REF( GRAPHIC_VERTEX_BUFFER );

    // .. CONSTRUCTORS

    GRAPHIC_VERTEX_BUFFER() : OBJECT()
    {

    }

    virtual ~GRAPHIC_VERTEX_BUFFER()
    {

    }

    // .. METHODS

    static VOID EnableVertexArray( const REAL *pointer, const COUNT component_count, const COUNT stride = 0 )
    {
    	glEnableClientState( GL_VERTEX_ARRAY );
    	glVertexPointer( component_count, GL_FLOAT, stride, pointer );
    }

    static VOID EnableColorArray( const REAL *pointer, const COUNT component_count, const COUNT stride = 0 )
    {
    	glEnableClientState( GL_COLOR_ARRAY );
    	glColorPointer( component_count, GL_FLOAT, stride, pointer );
    }

    static VOID EnableTexCoordArray( const REAL *pointer, const COUNT component_count, const COUNT stride = 0 )
    {
    	glEnableClientState( GL_TEXTURE_COORD_ARRAY );
    	glTexCoordPointer( component_count, GL_FLOAT, stride, pointer );
    }

    static VOID EnableNormalArray( const REAL *pointer, const COUNT stride = 0 )
    {
    	glEnableClientState( GL_NORMAL_ARRAY );
    	glNormalPointer( GL_FLOAT, stride, pointer );
    }

    static VOID EnableArray( const REAL *pointer, GLenum gl_format )
    {
    	// :TODO: Remove?
    	glEnableClientState( GL_TEXTURE_COORD_ARRAY );
    	glEnableClientState( GL_VERTEX_ARRAY );
    	glInterleavedArrays( gl_format, 0, pointer );
    }

    static VOID Draw( const COUNT vertex_count )
    {
    	glDrawArrays( GL_TRIANGLES, 0, vertex_count  );
    	DEBUG_CheckOpenGL();
    	glDisableClientState( GL_VERTEX_ARRAY );
    	glDisableClientState( GL_COLOR_ARRAY );
    	glDisableClientState( GL_TEXTURE_COORD_ARRAY );
    	glDisableClientState( GL_NORMAL_ARRAY );
    }

    // .. EXTENSIONS METHODS

    // :TODO: Implement VBOs.

    static PFNGLGENBUFFERSARBPROC
		glGenBuffers;
    static PFNGLBINDBUFFERARBPROC
		glBindBuffer;
    static PFNGLBUFFERDATAARBPROC
		glBufferData;
    static PFNGLDELETEBUFFERSARBPROC
		glDeleteBuffers;

    // -- PRIVATE

private :

    // .. ATTRIBUTES

};
/*--------------------------------------------------------------------------------*/
#endif
